<?php

namespace JsonLowCode\UI;

use JsonLowCode\Schema;
use JsonLowCode\Traits\Events\HasOnFinish;
use JsonLowCode\Traits\Props\HasActive;
use JsonLowCode\Traits\Props\HasAffix;
use JsonLowCode\Traits\Props\HasColor;
use JsonLowCode\Traits\Props\HasDuration;
use JsonLowCode\Traits\Props\HasMax;
use JsonLowCode\Traits\Props\HasShow;
use JsonLowCode\Traits\Props\HasType;
use JsonLowCode\Traits\Props\HasValue;

/**
 * Countdown 倒计时组件
 * ref-methods:  reset () => void
 * @method static Countdown make(bool|null $active = null, string|int|null $duration = null, string|int|null $precision = null) Countdown组件
 */
class Countdown extends Schema
{

    protected string $componentName = "NCountdown";

    use HasDuration, HasActive;

    use HasOnFinish;

    /**
     * @param bool|null $active
     * @param string|int|null $duration
     * @param string|int|null $precision
     */
    public function __construct(bool|null $active = null, string|int|null $duration = null, string|int|null $precision = null)
    {
        parent::__construct();
        $active!=null && $this->active($active);
        $duration!=null && $this->duration($duration);
        $precision!=null && $this->precision($precision);
    }

    /**
     * 倒计时的秒显示的精度
     * @param int|string $precision
     * @return $this
     */
    public function precision(string|int $precision = 0|1|2|3): static
    {
        return $this->prop('precision', $precision);
    }


    /**
     * 时间的渲染函数
     * @param string $value (props: { hours: number, minutes: number, seconds: number, milliseconds: number }) => VNodeChild
     * @return $this
     */
    public function render(string $value = "(props)=>{}"): static
    {
        return $this->events('render', $value);
    }
}
